package com.lin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.mapper.DFileMapper;
import com.lin.mapper.SCellMapper;
import com.lin.pojo.DFile;
import com.lin.pojo.PageVo;
import com.lin.pojo.SCell;
import com.lin.pojo.SysUsers;
import com.lin.service.SCellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SCellServiceImpl extends ServiceImpl<SCellMapper, SCell> implements SCellService {
    @Autowired
    SCellMapper sCellMapper;
    @Autowired
    DFileMapper dFileMapper;
    @Override
    public PageVo<SCell> querySCellbycond(SCell sCell, int pageno, int pagesize) {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<SCell> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<SCell>(pageno,pagesize);
        //条件查询
        QueryWrapper<SCell> queryWrapper =new QueryWrapper<SCell>();
        if(StringUtils.isNotBlank(sCell.getProductName())){
            queryWrapper.like("PRODUCT_NAME",sCell.getProductName());
        }
       /* if(person.getBirthday()!=null){
            //查询生日 大于当前指定日期的
            queryWrapper.gt("birthday",person.getBirthday());
        }*/
        Page<SCell> page1 = this.page(page,queryWrapper);
        PageVo<SCell> pageVo = new PageVo<SCell>();
        pageVo.setTotal(page1.getTotal());
        pageVo.setRows(page1.getRecords());
        return pageVo;
    }

    @Override
    public PageVo<SCell> querySCellbycondwangyingliang(SCell sCell, int pageno, int pagesize) {
        Page<SCell> page = new Page<SCell>(pageno,pagesize);
        //条件查询
        QueryWrapper<SCell> queryWrapper =new QueryWrapper<SCell>();
        if(StringUtils.isNotBlank(sCell.getProductName())){
            queryWrapper.like("PRODUCT_NAME",sCell.getProductName());
        }
        if(StringUtils.isNotBlank(sCell.getCheckTag())){
            queryWrapper.eq("CHECK_TAG",sCell.getCheckTag());
        }
        if(StringUtils.isNotBlank(sCell.getProductId())){
            queryWrapper.eq("PRODUCT_ID",sCell.getProductId());
        }
        if(StringUtils.isNotBlank(sCell.getFirstKindName())){
            queryWrapper.like("FIRST_KIND_NAME",sCell.getFirstKindName());
        }
        if(StringUtils.isNotBlank(sCell.getSecondKindName())){
            queryWrapper.like("SECOND_KIND_NAME",sCell.getSecondKindName());
        }
        if(StringUtils.isNotBlank(sCell.getSecondKindName())){
            queryWrapper.like("THIRD_KIND_NAME",sCell.getSecondKindName());
        }
        Page<SCell> page1 = this.page(page,queryWrapper);
        PageVo<SCell> pageVo = new PageVo<SCell>();
        pageVo.setTotal(page1.getTotal());
        pageVo.setRows(page1.getRecords());
        return pageVo;
    }

    @Override
    public SCell querySCellbyid(int id) {
        return sCellMapper.querySCellbyid(id);
    }

    @Override
    public Map addSCell(SCell sCell) {
        //
       /* sCell.setStoreId("2");*/
        DFile dFile=new DFile();

        dFile=dFileMapper.queryDFilebyid(sCell.getId());
        sCell.setFirstKindName(dFile.getFirstKindName());
        sCell.setSecondKindName(dFile.getSecondKindName());
        sCell.setThirdKindName(dFile.getThirdKindName());
        System.out.println(dFile);
        sCell.setCheckTag("S002-0");
        boolean num = this.save(sCell);
        //int num = personMapper.insert(person);
        Map map =new HashMap();
        map.put("code","0");
        map.put("msg","添加失败");
        if(num){
            map.put("code","1");
            map.put("msg","添加成功");
        }
        return map;
    }

    @Override
    public Map upSCell(SCell sCell) {
        sCell.setCheckTag("S002-1");
        int num=sCellMapper.updateById(sCell);
        Map map=new HashMap();
        map.put("code","0");
        map.put("msg","审核未通过");
        if (num==1){
            map.put("code","1");
            map.put("msg","审核通过");
        }
        return map;
    }

    @Override
    public Map upSCell01(SCell sCell) {
        sCell.setCheckTag("S002-0");
        int num=sCellMapper.updateById(sCell);
        Map map=new HashMap();
        map.put("code","0");
        map.put("msg","审核未通过");
        if (num==1){
            map.put("code","1");
            map.put("msg","审核通过");
        }
        return map;
    }

    @Override
    public List<SCell> queryfifstkindscellname() {
        return sCellMapper.queryfifstkindscellname();
    }



}
